$(function () {
//    $("#jqGrid").jqGrid({
//        url: '../sys/log/list',
//        datatype: "json",
//        colModel: [			
//			{ label: 'id', name: 'id', width: 30, key: true },
//			{ label: '用户名', name: 'username', width: 50 }, 			
//			{ label: '用户操作', name: 'operation', width: 70 }, 			
//			{ label: '请求方法', name: 'method', width: 150 }, 			
//			{ label: '请求参数', name: 'params', width: 80 }, 			
//			{ label: 'IP地址', name: 'ip', width: 70 }, 			
//			{ label: '创建时间', name: 'createDate', width: 90 }			
//        ],
//		viewrecords: true,
//        height: 385,
//        rowNum: 10,
//		rowList : [10,30,50],
//        rownumbers: true, 
//        rownumWidth: 25, 
//        autowidth:true,
//        multiselect: false,
//        pager: "#jqGridPager",
//        jsonReader : {
//            root: "list",
//            page: "currPage",
//            total: "totalPage",
//            records: "totalCount"
//        },
//        prmNames : {
//            page:"page", 
//            rows:"limit", 
//            order: "order"
//        },
//        gridComplete:function(){
//        	//隐藏grid底部滚动条
//        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
//        }
//    });
	   var grid = $("#jqGrid").kendoGrid({
         dataSource: {
             type: "json", 
             transport: {
                 read: {
                	url:"/demo/sys/log/list",
                    contentType : "application/json",
                    dataType : "json"
                 },
                 create: {
                	 url:"/demo/sys/log/save",
                     contentType : "application/json",
                     dataType : "json",
                     type: 'POST'                     
                 },
                 update: {
                	 url:"/demo/sys/log/save",
                     contentType : "application/json",
                     dataType: "json",
                     type: 'POST'
                 },
                 parameterMap : function(options, opType) {
             	    if (opType == "create" || opType=="update") {
             	        return kendo.stringify(options);
             	    }
             	    if(opType =="read"){
             	    	
             	        return options;
             	    }
//             	  return options;
             }
            
          },
          requestEnd: function(e) {
              var response = e.response;
              if(response){
                  var type = e.type;
                  if(type !='read'){
                      var status = response.status;
                      if(status == 200){
                          //lert(response.message);
                          this.read();
                      } else {
                          alert(response.message);
                      }
                  }
              }else{
                  alert("服务器异常，请重试！");
              }
              
          },
             schema: {
            	  data: "page.list",
                  total: "page.totalCount",
                 model: { 
                     fields: { 
                    	 username: { type: "string" }, 
                    	 operation: { type: "string" }, 
                    	 method: { type: "string" }, 
                    	 params: { type: "string" }
                     } 
                 } 
             }, 
//             batch: true,
             pageSize: 20,
             serverPaging: true,
             serverSorting: true,
             serverFiltering: true,
             scrollable: {virtual : true }
         },
         pageable: true,
         selectable: "multiple",
         height: 600,
         toolbar: ["create", "save", "cancel"], 
//         editable: "inline",
//         groupable: true,
         sortable: true,
         filterable: true,
         columnMenu: true,
         pageable: {
        	 pageSize : 20,// 一页显示多少行数据  
             previousNext : true,// 是否允许有上一页、下一页、首页、尾页摁扭  
             numeric : true,// 是否显示翻页处的页数按钮  
             buttonCount : 5,// 限制页数按钮的显示个数  
             input : false,// 是否显示输入页数的文本框  
             refresh : true,// 是否允许刷新页面  
             pageSizes : true,// 是否允许调整一页显示的行数，可设置[5, 10, 15]  
             messages : {  
                 display : "显示  {0}-{1} 条数据 共 {2} 条数据",  
                 empty : "没有数据",  
                 itemsPerPage : "选择显示行数",  
                 refresh : "刷新",  
                 previous : "上一页",  
                 next : "下一页",  
                 last : "尾页",  
                 first : "首页"  
             }
         },
         columns: [ {  
             field: "rowNumber",  
             title: "序号",  
             template: "<span class='row-number'></span>",
             width:120
         },{
             field: "username",
             title: "用户",
             filterable: { multi: true }
         }, {
             field: "operation",
             title: "操作",
             filterable: { multi: true }
         }, {
             field: "method",
             title: "方法",
             filterable: { multi: true }
         }, {
             field: "params",
             title: "参数",
             width: 200
         }],
         dataBound: function () {  
             var rows = this.items();  
             var page = this.pager.page() - 1;  
             var pagesize = this.pager.pageSize();  
             $(rows).each(function () {  
                 var index = $(this).index() + 1 + page * pagesize;  
                 var rowLabel = $(this).find(".row-number");  
                 $(rowLabel).html(index);  
             });  
         },  
         editable: true
     });

	 $("#searchBut").click(function () {
//         grid.data("kendoGrid").dataSource.filter(
////             { field: "op1eration", value: "123" }
//        		 { "username":"1"}
//       );
         grid.data("kendoGrid").dataSource.query( 
        		 { "username":"admin",
        			  page: 1,
        			  pageSize: 3}
        		 
         );
     });
});

